package com.ctsi.sms.service;

import com.ctsi.commons.util.UtilValidate;
import com.ctsi.commons.util.response.Page;
import com.ctsi.framework.mybatis.support.MybatisGenericDao;
import com.ctsi.sms.entity.SmsEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @auth:wgf
 * @description :
 * @Date: 2019/2/15
 */

@Service
public class SmsService {

    private static final Logger logger=LoggerFactory.getLogger(SmsService.class);
    @Autowired
    private MybatisGenericDao dao;

    /**
     * 添加
     */
    public void insertSms(SmsEntity smsEntity){
        if(UtilValidate.isEmpty(smsEntity.getMlid()))
        logger.debug("insert {}",smsEntity);
        dao.insert(smsEntity);
    }
    /**
     * 根据mlid获取短信详情
     */
    public SmsEntity selectSmsById(String mlid){
        logger.debug("selectSmsById {}",mlid);
        return (SmsEntity) dao.queryForObject(SmsEntity.class.getName()+".selectSmsById",mlid);
    }
    /**
     * 修改短信发送状态
     */
    public int updateByPrimaryKeySelective(SmsEntity smsEntity){
        logger.debug("updateByPrimaryKeySelective {}",smsEntity);
        return dao.update(SmsEntity.class.getName()+".updateByPrimaryKeySelective", smsEntity);
    }
    /**
     *  查询信息列表
     */
    public Page<SmsEntity> querySmsList(Map<String,Object> param , int start , int pageSize){
        logger.debug("querySmsList {}",param);
        if(pageSize<0||pageSize>2000)
            pageSize=Page.DEFAULT_PAGE_SIZE;
        if(start!=-1)
            return dao.queryPage(SmsEntity.class.getName()+".querySmsList", param, start, pageSize);
        else{
            throw new RuntimeException("参数不正确 !!");
        }
    }

}
